n, f = list(map(int, input().split()))
store = []
class day:
def __init__(self, K_i, L_i):
self.client = L_i
self.products = K_i
for i in range(n):
K_i, L_i = list(map(int, input().split()))
store.append(day(K_i, L_i))
store = sorted(store, key=lambda x : min(2 * x.products, x.client) - min(x.products, x.client), reverse= True)
for i in range(f):
store[i].products = store[i].products * 2
sum = 0
for i in store:
if i.products > i.client:
sum += i.client
else:
sum += i.products
print(sum)
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<cmath>
#include<set>
#include <numeric>
using namespace std;
const long double pi = 2 * acos(0.0);
#define all(v) ((v).begin()),((v).end())
#define sz(v) (int)(v.size())
#define p_b push_back
#define fi first
#define se second
#define ma make_pair
#define oo 1e8
typedef long long ll;
typedef vector< vector<int> >vv;
typedef vector<ll>vi;
typedef vector<bool> vb;
#include<stdio.h>
int x_ax[] = {0,0,1,-1,-1,-1,1,1},
y_ax[] = {1,-1,0,0,1,-1,1,-1};
bool valid(int r, int c, int n, int m) {
return !(r < 0 || r >= n || c < 0 || c >= m);
}
int gcd(int a, int b) {
if (!b)return a;
return gcd(b, a % b);
}
int main() {
ll n,f,ans=0;cin>>n>>f;
vector<ll>p(n);
for(ll x=0,fr,sc;x<n;x++){cin>>fr>>sc;
ans+=min(fr,sc);
if(fr<sc&&(2*fr)<=sc)p[x]=(2*fr)-fr;
else if(fr<sc&&(2*fr)>sc)p[x]=sc-fr;
else p[x]=0;
}
sort(all(p),greater<ll >());
for(ll x=0;x<f;x++)ans+=p[x];
cout<<ans;
}
766B - Mahmoud and a Triangle | 1618C - Paint the Array |
469A - I Wanna Be the Guy | 1294A - Collecting Coins |
1227A - Math Problem | 349A - Cinema Line |
47A - Triangular numbers | 1516B - AGAGA XOOORRR |
1515A - Phoenix and Gold | 1515B - Phoenix and Puzzle |
155A - I_love_username | 49A - Sleuth |
1541A - Pretty Permutations | 1632C - Strange Test |
673A - Bear and Game | 276A - Lunch Rush |
1205A - Almost Equal | 1020B - Badge |
1353A - Most Unstable Array | 770A - New Password |
1646B - Quality vs Quantity | 80A - Panoramix's Prediction |
1354B - Ternary String | 122B - Lucky Substring |
266B - Queue at the School | 1490A - Dense Array |
1650B - DIV + MOD | 1549B - Gregor and the Pawn Game |
553A - Kyoya and Colored Balls | 1364A - XXXXX |